<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<style>
  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(to right, #3498db, darkturquoise);
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    /* 确保 header 在最上层 */
    height: 80px;
    font-size: 20px;
    font-weight: bold;
    border-bottom: 1px solid #ccc;
  }

  .user-info {
    display: flex;
    align-items: center;
    margin-right: 40px;
  }

  .dropdown-toggle {
    font-size: 14px;
    cursor: pointer;
  }

  .dropdown-menu {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 60px;
    box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
    z-index: 1;
  }

  .dropdown:hover .dropdown-menu {
    display: block;
  }

  .menu-item {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    font-size: 14px;
  }

  .menu-item:hover {
    background-color: #f1f1f1;
  }
</style>


<div class="header">
  <h3 style="color:black;margin-left: 40px">天天向上</h3>
  <div class="user-info">
    <img src="${user_key.avatar}" style="width: 30px;border-radius:50%;margin-right: 10px;">
    <div class="dropdown">
      <span class="dropdown-toggle">${user_key.nickname} &#9660;</span>
      <div class="dropdown-menu">
        <c:if test="${user_key.status}">
          <a class="menu-item" href="Manager.jsp">后台管理</a>
        </c:if>
        <a class="menu-item" href="javascript:void(0)" onclick="showMessage()">个人信息</a>
        <a class="menu-item" href="javascript:void(0)" onclick="handleLogout()">退出</a>
      </div>
    </div>
  </div>
</div>

<script>

  function showMessage() {
    var dropdownMenu = document.getElementById("dropdownMenu");
    var mainList = document.getElementsByClassName('main')
    var message = document.getElementById('message')
    for (let i = 0; i < mainList.length; i++) {
      mainList[i].style.display = 'none'
    }
    message.style.display = 'block'
  }

  function handleLogout() {
    var xhr = new XMLHttpRequest()
    xhr.onload = function () {
      if (xhr.status === 200) {
        window.location.href = "Login.jsp"
      }
    }

    xhr.open("POST", "account?type=2", true)
    xhr.send()
  }

</script>


